package com.framework.aqs;

import java.util.ArrayList;
import java.util.List;

/**
 * @author duanzhizhou
 * @date 2025/4/10
 */
public class main {
    
    public static void main(String[] args) throws InterruptedException {
        int[] x = new int[1];
        List<Thread> list = new ArrayList<>();
        MyLock lock = new MyLock();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                lock.lock();
                try {
                    Thread.sleep(100);
                    for (int j = 0; j < 1000; j++) {
                        x[0]++;
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } finally {
                    lock.unlock();
                }
            });
            thread.start();
            list.add(thread);
        }
        for (Thread thread : list) {
            thread.join();
        }
        System.out.println(x[0]);
    }
}
